import { _decorator, Component, game, math, PhysicsSystem2D } from 'cc';
import { EventManager } from './manager/EventManager';
import { EventEnum } from './enum/EventEnum';
import Mgr from './manager/Mgr';
import { ControllerManager } from './manager/ControllerManager';
import { CacheManager } from './manager/CacheManager';
import { ConfigManager } from './manager/ConfigManager';
import { LoaderManager } from './manager/LoaderManager';
import { LayerManager } from './manager/LayerManager';
import { SDK } from './SDK/SDK';
import { Main } from './Main';
import { GameLoadingView } from './common/loading/GameLoadingView';
import TweenManager from './common/TweenManager';
const { ccclass, property } = _decorator;
@ccclass('GameStart')
export class GameStart extends Component {
    private _main: Main;
    start() {
        PhysicsSystem2D.instance.enable = true;
        PhysicsSystem2D.instance.gravity = new math.Vec2(0, -2000);
        PhysicsSystem2D.instance.allowSleep = false;
        
        Mgr.loader = new LoaderManager();
        LayerManager.init();

        this._main = new Main();
        EventManager.addListener(EventEnum.OnGameResLoadComplete, this.onGameResLoadComplete, this);
        EventManager.addListener(EventEnum.OnUILoading, this.onUILoading, this);
        EventManager.addListener(EventEnum.OnUILoadComplete, this.onUILoadComplete, this);

        console.log("帧率：" + game.frameRate)
    }

    update(deltaTime: number) {
        TweenManager.Update(deltaTime);
    }

    private onUILoading() {
        GameLoadingView.showLoading();
    }

    private onUILoadComplete() {
        GameLoadingView.hideLoading();
    }

    private onGameResLoadComplete() {
        ConfigManager.init();
        CacheManager.init();

        Mgr.Init();
        ControllerManager.init();

        SDK.Init();

        console.log("资源加载完成，显示主界面");
        this._main.show();
        // this._main.active = true;
    }
}


